package org.zjsru.user.web;


import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.zjsru.user.pojo.PatternPropterties;
import org.zjsru.user.pojo.User;
import org.zjsru.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Locale;

@Slf4j
@RestController
@RefreshScope
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;
    @Value("${custom.welcomeMessage}")
    private String welcomeMessage;

    @GetMapping("/welcome")
    public String getWelcomeMessage() {
        return welcomeMessage;
        /*return "welcomeMessage";*/
    }

    @Value("${feature.enableDiscount:false}")
    private boolean enableDiscount;

    @GetMapping("/discount")
    public String checkDiscount() {
        return enableDiscount ? "折扣功能已开启" : "折扣功能已关闭";
    }

//    @Value("${pattern.dateformat}")
//    private String dateFormat;
//
//    @Autowired
//    private PatternPropterties properties;
    /**
     * 路径： /user/110
     *
     * @param id 用户id
     * @return 用户
     */
    @GetMapping("/{id}")
    public User queryById(@PathVariable("id") Long id) throws InterruptedException {
        Thread.sleep(6000);
        return userService.queryById(id);
    }
//    @GetMapping("/now")
//    public String now() {
//        return LocalDate.now().format(
//                DateTimeFormatter.ofPattern(dateFormat, Locale.CHINA)
//        );
//    }
//    @GetMapping("/now2")
//    public String now2() {
//        return LocalDate.now().format(
//                DateTimeFormatter.ofPattern(properties.getDateformat(), Locale.CHINA)
//        );
//    }
/*    @GetMapping("/{userid}")
    public User queryUserWithOrderByUserId(@PathVariable("userid") Long userid) throws InterruptedException {

        *//*Thread.sleep(6000);*//*
        return userService.queryById(userid);
    }*/

}
